﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SmartEP.Presenter;
using SmartEP.DTO;

namespace SmartDesktop
{
    public partial class CheckInView : UserControl, ICheckInView
    {
        private PatientCarePresenter _presenter;

        #region
        private int _patientId;
        private Physician _preferedPhysician;
        #endregion

        public CheckInView(PatientCarePresenter presenter)
        {
            InitializeComponent();
            this.Name = "Patient Check-In";
            this._presenter = presenter;
        }

        #region Property
        public String FirstName
        {
            get
            {
                return txtFirstName.Text; 
            }
            set 
            { 
                txtFirstName.Text = value; 
            }
        }

        public String LastName
        {
            get 
            { 
                return txtLastName.Text;
            }
            set 
            { 
                txtLastName.Text = value;
            }
        }

        public String PhoneNumber
        {
            get 
            { 
                return txtPhone.Text; 
            }
            set 
            { 
                txtPhone.Text = value; 
            }
        }

        public Physician PreferedPhysician
        {
            get 
            { 
                return _preferedPhysician; 
            }
            set
            {
                _preferedPhysician = value;
            }
        }

        public IList<CheckIn.ServiceType> ServicesRequested
        {
            get
            {
                IList<CheckIn.ServiceType> servicesRequested = new List<CheckIn.ServiceType>();

                if (chkExam.Checked)
                {
                    servicesRequested.Add(CheckIn.ServiceType.Exam);
                }
                if (chkContact.Checked)
                {
                    servicesRequested.Add(CheckIn.ServiceType.PuchaseContact);
                }
                if (chkEyewear.Checked)
                {
                    servicesRequested.Add(CheckIn.ServiceType.PuchaseEyewaer);
                }
                if (chkFitting.Checked)
                {
                    servicesRequested.Add(CheckIn.ServiceType.Fiting);
                }
                if (chkOther.Checked)
                {
                    servicesRequested.Add(CheckIn.ServiceType.Other);
                }

                return servicesRequested;
            }
            set 
            {
                foreach (CheckIn.ServiceType item in value)
                {
                    switch (item)
                    {
                        case CheckIn.ServiceType.Exam:
                            chkExam.Checked = true;
                            break;
                        case CheckIn.ServiceType.PuchaseEyewaer:
                            chkEyewear.Checked = true;
                            break;
                        case CheckIn.ServiceType.PuchaseContact:
                            chkContact.Checked = true;
                            break;
                        case CheckIn.ServiceType.Fiting:
                            chkFitting.Checked = true;
                            break;
                        case CheckIn.ServiceType.Other:
                            chkOther.Checked = true;
                            break;
                    }
                }
            }
        }

        public String ReasonForVisit
        {
            get 
            { 
                return txtReason.Text; 
            }
            set
            { 
                txtReason.Text = value;
            }
        }

        public CheckIn.VisitScheduleType VisitSchedule
        {
            get
            {
                if (radAppointment.Checked)
                {
                    return CheckIn.VisitScheduleType.Appointment;
                }
                else
                {
                    return CheckIn.VisitScheduleType.WalkIn;
                }                
            }
            set 
            {
                if (value == CheckIn.VisitScheduleType.Appointment)
                {
                    radAppointment.Checked = true;
                }
                else
                {
                    radWalkin.Checked = true;
                }
            }
        }

        public DateTime Birthday
        {
            get
            {
                return dtpBirthday.Value; 
            }
            set
            {
                dtpBirthday.Value = value; 
            }
        }
        #endregion

        #region Private Methods

        private void btnSearch_Click(object sender, EventArgs e)
        {
            PatientSearchDialog frm = new PatientSearchDialog(this);
            frm.ShowDialog();
        }

        public Patient SelectPatient
        {
            set
            {
                _patientId = value.Id;
                txtFirstName.Text = value.FirstName;
                txtLastName.Text = value.LastName;
                txtPhone.Text = value.AltPhone.Number;
            }
        }

        #endregion

        #region

        public void AddNewCheckIn(CheckIn checkin)
        {
        }

        private void btnCheckIn_Click(object sender, EventArgs e)
        {            
        }

        #endregion

        private void btnNewPatient_Click(object sender, EventArgs e)
        {
            ResetUserControl();
        }

        private void ResetUserControl()
        {
            txtFirstName.Clear();
            txtLastName.Clear();
            txtPhone.Clear();
            txtReason.Clear();
            chkExam.Checked = false;
            chkEyewear.Checked = false;
            chkContact.Checked = false;
            chkOther.Checked = false;
            chkFitting.Checked = false;
        }
    }
}